package com.hong610.net.http.client;

import com.hong610.net.config.Config;
import com.hong610.net.connection.HttpConnection;
import com.hong610.net.enums.NetAgreement;
import com.hong610.net.enums.NetHandle;
import com.hong610.net.util.StringUtils;
import org.apache.http.client.HttpClient;
/**
 * Client基础配置信息
 * Created by Hong on 2016/12/31.
 */
@SuppressWarnings("deprecation")
public abstract class Client {

	/**请求方式**/
	protected NetAgreement netAgreement = NetAgreement.HTTP;

	/**数据处理方式**/
	protected NetHandle handle = NetHandle.NORMAL;
	
	/**访问URL**/
	protected String url = "";
	
	/**编码**/
	protected String charset = Config.CHARSET;

	/**HTTPS证书地址**/
	protected String cret = null;

	/**证书密码**/
	protected String cret_password = null;

	/**
	 * 得到HttpClient
	 * @return HttpClient
	 */
	protected HttpClient getHttpClient() {
		HttpClient httpClient = null;
		if(netAgreement == NetAgreement.HTTPS_CRET) {
			if(StringUtils.isEmpty(cret) || StringUtils.isEmpty(cret_password))
				throw new RuntimeException("没有证书！");
			httpClient = HttpConnection.getHttpsConnenctionCret(cret, cret_password);
		}else{
			httpClient = HttpConnection.getConnenction(netAgreement);
		}
		return httpClient;
	}
	
}
